/**
 * cone-service: router.js
 * Description: 自动注册路由
 * Time: 2022/6/30 17:45
 */
const glob = require('glob')
const path = require('path')

module.exports = (app) => {
    const rpath = path.resolve(process.cwd(), 'routers', '**/*.js')
    const allfiles = glob.sync(rpath)
    allfiles.filter(value => (value.indexOf('index.js') === -1))
        .map(routerPath => {
            const router = require(routerPath)
            app.use(router.routes()).use(router.allowedMethods())
        })
}
